{extend name="default/base/base_seller" /}
{block name="seller_main"}

<style type="text/css">

	.layui-btn {
	    background-color: #FF7159 !important;
	}
    .layui-btn:hover {
	    opacity: .8;
	    filter: alpha(opacity=80);
	    color: #fff;
    }
	a:hover {
	    color: #777;
	}
	.layui-btn-xs {
	    height: 22px;
	    line-height: 22px;
	    padding: 0 5px;
	    font-size: 12px;
	}
	.layui-btn {
	    display: inline-block;
	    height: 27px;
	    line-height: 27px;
	    padding: 0 7px;
	    background-color: #009688;
	    color: #fff;
	    white-space: nowrap;
	    text-align: center;
	    font-size: 10px;
	    border: none;
	    border-radius: 2px;
	    cursor: pointer;
	}
	.layui-btn, .layui-input, .layui-select, .layui-textarea, .layui-upload-button {
	    outline: 0;
	    -webkit-appearance: none;
	    transition: all .3s;
	    -webkit-transition: all .3s;
	    box-sizing: border-box;
	}
	.layui-layer-content{
	    margin-left: 20px;
	}
}
</style>
 <div class="dssc-form-default">
    <form id="add_form" action="{if isset($edit_goods_sign)}{:url('Sellerareabill/edit_waybill')}{else/}{:url('Sellerareabill/waybill_save')}{/if}" method="post" enctype="multipart/form-data">
        <input type="hidden" name="waybill_id" value="{$waybill_info.waybill_id|default=''}">
        <input type="hidden" name="old_waybill_image" value="{$waybill_info.waybill_image|default=''}">
        <div style="display: none;">
        <dl>
            <dt><i class="required">*</i>{$Think.lang.template_name}{$Think.lang.ds_colon}</dt>
            <dd>
                <input type="text" value="{$waybill_info.waybill_name|default=''}" name="waybill_name" id="waybill_name" class="w120 text">
                <span></span>
            </dd>
        </dl>

        <dl>
            <dt><i class="required">*</i>是否免除服务费:</dt>
            <dd>  <select name="is_bao">
                    <option value="1" {if isset($waybill_info.is_bao) &&$waybill_info.is_bao eq '1'}selected{/if}>免除</option>
                     <option value="0" {if isset($waybill_info.is_bao) &&$waybill_info.is_bao neq '1'}selected{/if}>不免除</option>
                </select>
                <span></span>
               </dd>
        </dl>
         <dl>
            <dt><i class="required">*</i>是否默认:</dt>
            <dd>
             <select name="is_default">
                    <option value="1" {if isset($waybill_info.is_default) &&$waybill_info.is_default eq '1'}selected{/if}>是</option>
                     <option value="0" {if isset($waybill_info.is_default) &&$waybill_info.is_default neq '1'}selected{/if}>否</option>
                </select>
                <span></span>
            </dd>
        </dl>

        <!--默认费用-->
        <dl>
            <dt>默认费用：</dt>
            <dt><i class="required">*</i>安装费：</dt>
            <dd  style="width: 200px;">
                <input type="text" value="{$waybill_info.install_money|default=''}" name="install_money" id="install_money" class="w60 text"><em class="add-on">元</em>
                <span></span>
                <p class="hint">单位：元</p>
            </dd>
            <dt><i class="required">*</i>维修费：</dt>
            <dd style="width: 200px;">
                <input type="text" value="{$waybill_info.mintain_money|default=''}" name="mintain_money" id="mintain_money" class="w60 text"><em class="add-on">元</em>
                <span></span>
                <p class="hint">单位：元</p>
            </dd>

        </dl>
        <!--默认费用，为了样式，所以这么写-->
        <dl>
            <dt></dt>
            <dt><i class="required">*</i>保养费：</dt>
            <dd style="width: 200px;">
                <input type="text" value="{$waybill_info.upkeep_money|default=''}" name="c_heavy" id="upkeep_money" class="w60 text"><em class="add-on">元</em>
                <span></span>
                <p class="hint">单位：元</p>
            </dd>

            <dt><i class="required">*</i>拆移费：</dt>
            <dd style="width: 200px;">
                <input type="text" value="{$waybill_info.move_money|default=''}" name="c_heavy" id="move_money" class="w60 text"><em class="add-on">元</em>
                <span></span>
                <p class="hint">单位：元</p>
            </dd>

        </dl>

        <dl>
            <dt><i class="required">*</i>是否启用</dt>
            <dd>
                  <select name="status" id='area_type1'>
                    <option value="1" {if isset($waybill_info.status) &&$waybill_info.status neq '0'}selected{/if}>启用</option>
                     <option value="0" {if isset($waybill_info.status) &&$waybill_info.status eq '0'}selected{/if}>不启用</option>
                </select>
                <span></span>
            </dd>
        </dl>
         <dl>
            <dt><i class="required">*</i>地区类型：</dt>
            <dd>
                 <select name="area_type" id='area_type'>
                    <option value="0" {if isset($waybill_info.area_type) &&$waybill_info.area_type neq '1'}selected{/if} select>全部地区</option>
                     <option value="1" {if isset($waybill_info.area_type) &&$waybill_info.area_type eq '1'}selected{/if}>部分地区</option>
                </select>
                <span></span>
            </dd>
        </dl>
        </div>
<!-- 判断是修改还是添加 -->
{if isset($edit_goods_sign)&&isset($area)}

 <dl class='area'>
           <dd><div class="div-none" >
            <div class="layui-input-block">
                <table class="dssc-default-table" style="margin-left: 70px;">
                    <thead>
                    <tr>
                        <th>选择地区</th>
                        <th>安装费</th>
                        <th>维修费</th>
                        <th>保养费</th>
                        <th>拆移费</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="view">
                        {foreach name="area" key='key' item="v" }
                    <tr data-id="0">
                        <td style="width: 100px;" >
                            <input type='hidden' name="area_id[{$key}]" class="area_id_list" value='{$v.area_id}' data_name='' id='0'>
                            {if isset($v.area_name)}
                            <input type='hidden' name="area_name[{$key}]" value='{$v.area_name}' data_name='' id='0'>
                            <a href="javascript:void(0);"  style="color: #999">已选择地区：{$v.area_name}</a>
                            {else/}
                            <a href="javascript:void(0);"  style="color: #999">暂未选择</a>
                            {/if}
                        </td>
                        <td>
                            <label class="layui-form-label">安装费：</label>
                            <input type="text" style="width: 50px;" name="install_area_price[{$key}]" value={$v.install_area_price} required value="0" lay-verify="required" placeholder="" autocomplete="off" class="layui-input seller-inline-1">
                        </td>
                        <td>
                            <label class="layui-form-label">维修费：</label>
                            <input type="text" style="width: 50px;" name="mintain_money_price[{$key}]" value={$v.mintain_money_price} required value="0" lay-verify="required" placeholder="" autocomplete="off" class="layui-input seller-inline-1">
                        </td>
                        <td>
                            <label class="layui-form-label">保养费：</label>
                            <input type="text" style="width: 50px;" name="upkeep_money_price[{$key}]" value={$v.upkeep_money_price} required value="0" lay-verify="required" placeholder="" autocomplete="off" class="layui-input seller-inline-1">
                        </td>
                        <td>
                            <label class="layui-form-label">拆移费：</label>
                            <input type="text" style="width: 50px;" name="move_money_price[{$key}]" value={$v.move_money_price} required value="0" lay-verify="required" placeholder="" autocomplete="off" class="layui-input seller-inline-1">
                        </td>

                        <td>
                            <a class="layui-btn layui-btn-xs addarea-class">
                                添加地区
                            </a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs del-class" style="background-color: #393D49 !important;">
                                删除
                            </a>
                        </td>
                    </tr>
                    {/foreach}
                    </tbody>
                </table>
            </div>
        </div>
 <dd>

 </dl>

 {else/}
 <dl class='area'>
           <dd><div class="div-none" >
            <div class="layui-input-block">
                <table class="dssc-default-table" style="margin-left: 70px;">
                    <thead>
                    <tr>
                        <th>选择地区</th>
                        <th>安装费</th>
                        <th>维修费</th>
                        <th>保养费</th>
                        <th>拆移费</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="view">
                    <tr data-id="0">
                        <td style="width: 100px;">
                            <input type='hidden' name='area_id[0]' value='' data_name='' id='0'>
                            <a href="javascript:void(0);" class="selectArea" style="color: #46a751;">请选择地区</a>
                        </td>
                        <td>
                            <label class="layui-form-label">安装费：</label>
                            <input type="text" style="width: 50px;"  name="install_area_price[0]"  required value="0" lay-verify="required" placeholder="" autocomplete="off" class="layui-input seller-inline-1">
                        </td>
                        <td>
                            <label class="layui-form-label">维修费：</label>
                            <input type="text" style="width: 50px;" name="mintain_money_price[0]"  required value="0" lay-verify="required" placeholder="" autocomplete="off" class="layui-input seller-inline-1">
                        </td>
                        <td>
                            <label class="layui-form-label">保养费：</label>
                            <input type="text" style="width: 50px;" name="upkeep_money_price[0]"  required value="0" lay-verify="required" placeholder="" autocomplete="off" class="layui-input seller-inline-1">
                        </td>
                        <td>
                            <label class="layui-form-label">拆移费：</label>
                            <input type="text" style="width: 50px;" name="move_money_price[0]"  required value="0" lay-verify="required" placeholder="" autocomplete="off" class="layui-input seller-inline-1">
                        </td>
                        <td>
                            <a class="layui-btn layui-btn-xs addarea-class">
                                添加地区
                            </a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs del-class" style="background-color: #393D49 !important;">
                                删除
                            </a>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
 <dd>
 </dl>
{/if}


        <div class="bottom">
            <input type="submit" class="submit" value="{$Think.lang.ds_submit}">
        </div>
    </form>
</div>


<!-- 地区代码 -->
  <div class="list" style='display:none;margin-left: 20px;'  >
      <input style="margin-right: 8px;" type="checkbox"  id="checkboxs" name="checkall">全选
    <?php foreach($top_area as $k=>$v){ ?>
    <div class="top">

    <span style="font-family: 'dtreefont' !important;font-size: 16px;font-style: normal;-webkit-font-smoothing: antialiased;-webkit-tap-highlight-color: rgba(0,0,0,0);" class='select_choose dtreefont dtree-icon-jia dtree-theme-dtreefont dtree-theme-ficon' data-spread="close">
    </span>
    <input style="margin-right: 8px;" type="checkbox"  value="<?php echo $v['area_id']; ?>" class="top" area_deep="1" ids="<?php echo $v['last_ids']; ?>"  data_name="<?php echo $v['area_name']; ?>">
      <?php echo $v['area_name']; ?>
    <div class="sec<?php echo $v['area_id']; ?>" style='padding-left:20px; margin:10px;'></div>
    </div>
    <?php }?>
  </div>
 <script>
     //数组去重
     function unique(arr) {
         var ret = []

         for (var i = 0; i < arr.length; i++) {
             var item = arr[i]
             if (ret.indexOf(item) === -1) {
                 ret.push(item)
             }
         }

         return ret
     }

     //全选
     $(document).on('click','#checkboxs',function(){
         if($(this).prop('checked')) {
             $(".top").find('input:checkbox').prop("checked", true);
         } else {
             $(".top").find('input:checkbox').prop("checked", false);
         }

     });

     $(document).ready(function() {
         jQuery.validator.addMethod("checkFCodePrefix", function(value, element) {
             return this.optional(element) || /^[a-zA-Z]+$/.test(value);
         },'<i class="iconfont">&#xe64c;</i>{$Think.lang.prompt_information1}');
         $('#add_form').validate({
             errorPlacement: function(error, element){
                 $(element).nextAll('span').append(error);
             },
             rules : {
                 waybill_name : {
                     required    : true,
                 },
                 waybill_express : {
                     required    : true,
                 },
                 is_bao : {
                     required    : true,
                 },
                 is_default : {
                     required    : true,
                 },

                 f_heavy : {
                     required    : true,
                     number: true,
                     min: 0,
                 },
                 f_heavy_money : {
                     required    : true,
                     number: true,
                     min: 0,
                 },
                 c_heavy : {
                     required    : true,
                     number: true,
                     min: 0,
                 },
                 c_heavy_money : {
                     required    : true,
                     number: true,
                     min: 0,
                 },
                 home_price : {
                     required    : true,
                     number: true,
                     min: 0,
                 },

                 f_volume : {
                     required    : true,
                     number: true,
                     min: 0,
                 },
                 f_volume_money : {
                     required    : true,
                     number: true,
                     min: 0,
                 },
                 c_volume : {
                     required    : true,
                     number: true,
                     min: 0,
                 },
                 c_volume_money : {
                     required    : true,
                     number: true,
                     min: 0,
                 },
                /* money : {
                     number: true,
                     min: 0,
                 },*/
                 status : {
                     required    : true,
                 },
                 area_type : {
                     required    : true,
                 }
             },
             messages : {
                 waybill_name   : {
                     required    : '<i class="iconfont">&#xe64c;</i>不能为空',
                 },
                 waybill_express   : {
                     required    : '<i class="iconfont">&#xe64c;</i>不能为空'
                 },
                 is_bao   : {
                     required    : '<i class="iconfont">&#xe64c;</i>不能为空'
                 },
                 is_default   : {
                     required    : '<i class="iconfont">&#xe64c;</i>不能为空'
                 },

                 home_price   : {
                     required: '<i class="iconfont">&#xe64c;</i>不能为空',
                     number: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                     min: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                 },
                 f_heavy   : {
                     required: '<i class="iconfont">&#xe64c;</i>不能为空',
                     number: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                     min: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',

                 },
                 f_heavy_money   : {
                     required: '<i class="iconfont">&#xe64c;</i>不能为空',
                     number: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                     min: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                 },
                 c_heavy   : {
                     required: '<i class="iconfont">&#xe64c;</i>不能为空',
                     number: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                     min: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                 },
                 c_heavy_money   : {
                     required: '<i class="iconfont">&#xe64c;</i>不能为空',
                     number: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                     min: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                 },
                 f_volume   : {
                     required: '<i class="iconfont">&#xe64c;</i>不能为空',
                     number: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                     min: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',

                 },
                 f_volume_money   : {
                     required: '<i class="iconfont">&#xe64c;</i>不能为空',
                     number: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                     min: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                 },
                 c_volume   : {
                     required: '<i class="iconfont">&#xe64c;</i>不能为空',
                     number: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                     min: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                 },
                 c_volume_money   : {
                     required: '<i class="iconfont">&#xe64c;</i>不能为空',
                     number: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                     min: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                 },

                /* money   : {
                     required: '<i class="iconfont">&#xe64c;</i>不能为空',
                     number: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                     min: '<i class="iconfont">&#xe64c;</i>请设置正确的数值',
                 },*/
                 waybill_image   : {
                     required    : '<i class="iconfont">&#xe64c;</i>不能为空'
                 },
                 status   : {
                     required    : '<i class="iconfont">&#xe64c;</i>不能为空'
                 },
                 area_type  : {
                     required    : '<i class="iconfont">&#xe64c;</i>不能为空'
                 },

             }
         });

         $("form").submit(function(e){
             var res =  $("#add_form").valid();
             if(res){
                 var url = $('form').attr('action');
                 var area_id = $('input[name="area_id[0]"]').val();
                 var area_type = $("#area_type").val();
                 if(area_id==''&&area_type=='1'){
                     layer.msg('请设置销售区域');return false;
                 }else if(typeof area_id=='undefined'&&area_type=='1'){
                     layer.msg('请设置销售区域');return false;
                 }else{
                     $.ajax({
                         type: "POST",
                         url:url,
                         data:$('#add_form').serialize(),// 你的formid

                         error: function(request) {
                             alert("Connection error");
                         },
                         success: function(result) {
                             if(result.code==0){
                                 layer.msg(result.msg);
                                 location.href=result.url;return false;
                             }else{
                                 layer.msg(result.msg);
                                 location.href=result.url;return false;s

                             }
                         }
                     });
                     return false;


                 }return false;

             }
         });



     });

$(function(){

 {if isset($edit_goods_sign)&&isset($waybill_info.area_type)&& $waybill_info.area_type == 1}
  {else/}
  // $(".area").hide();
  {/if}

   $(document).on('change','#area_type',function(){
         var type = $(this).val();
            if (type == '1') {
                $(".area").show();
            } else {
                $(".area").hide();
            }
        });

   $(document).on('click', '.addarea-class', function() {
       $('input[type="checkbox"]:checked').each(function(){
           console.log($(this).attr('data_name'));
       });

            var lastId = $(this).parent().parent().parent().find('tr').last().attr('data-id');

            var id = parseInt(lastId) + 1;
            htmls='<tr data-id="'+id+'"><td><input type="hidden" id="'+id+'" data_name=""><a href="javascript:void(0); "class="selectArea" style="color: #46a751;">请选择地区</a></td><td><label class="layui-form-label">安装费：</label><input type="text" style="width: 50px;"  name="install_area_price['+id+']" required value="0" lay-verify="required"  autocomplete="off" class="layui-input seller-inline-1"></td><td><label class="layui-form-label">维修费：</label><input type="text" style="width: 50px;" name="mintain_money_price['+id+']" required value="0" lay-verify="required" autocomplete="off" class="layui-input seller-inline-1"></td><td><label class="layui-form-label">保养费：</label><input type="text" style="width: 50px;" name="upkeep_money_price['+id+']" required value="0" lay-verify="required"  autocomplete="off" class="layui-input seller-inline-1"></td><td><label class="layui-form-label">拆移费：</label><input type="text" style="width: 50px;" name="move_money_price['+id+']" required value="0" lay-verify="required" autocomplete="off" class="layui-input seller-inline-1"></td><td><a class="layui-btn layui-btn-xs addarea-class">添加地区</a>&nbsp;<a class="layui-btn layui-btn-danger layui-btn-xs del-class" style="background-color: #393D49 !important;">删除</a></td></tr>';
           $("#view").append(htmls);
        });

     $(document).on('click', '.del-class', function() {
            $(this).parent().parent().remove();
        });


   $(document).on('click', '.selectArea', function() {

        id = $(this).parent().parent().attr('data-id');
       var input  = $('.list').find('input').each(function(){
           $(this).attr('class','aaa');
   });
       var $list = $('.list').html();
       $('.list').find('input').each(function(){
           $(this).attr('class','');
       });
     obj = $(this);

     layer.confirm('',{
            title: '地区选择',
            type: 1,
            area: ['700px', '450px'],
            fixed: false,
            maxmin: true,
            btn: ['确认', '取消'],
            content :$list,
        }, function () {
            var chk_value =[];
            var data_names =[];
            $('input[type="checkbox"]:checked').each(function(){
                if($(this).attr('class') != 'aaa'){
                    return true;
                }
            chk_value.push($(this).attr('ids'));
            data_names.push($(this).attr('data_name'));
            });
             var area_name =  unique(data_names);
             if(chk_value==''){
                 layer.closeAll();
             }else{
                 html ='已选地区：'+area_name;
                 html+="<input type='hidden' name='area_id["+id+"]' value='"+chk_value+"'>";
                 html+="<input type='hidden' name='area_name["+id+"]' value='"+area_name+"'>";
                 $(".top").find('input:checkbox').prop("checked", false);
                 obj.parent().html(html);
                 layer.closeAll();
             }

        });

});




 $(document).on('click', '.select_choose', function() {
    var choose_id = $(this).next().val();
    var obj = $(this);
     $.ajax({
            type: 'POST',
            url: "{:url('Sellerareabill/ajax_area')}",
            cache: false,
            data: {choose_id:choose_id},
            dataType: 'json',
            success: function (data) {
                var htmls = '';
              $.each(data, function(k,v) {
                if(v.area_deep!=3){
                     htmls+='<span style="font-family: \'dtreefont\' !important;font-size: 16px;font-style: normal;-webkit-font-smoothing: antialiased;-webkit-tap-highlight-color: rgba(0,0,0,0);" class="select_choose dtreefont dtree-icon-jia dtree-theme-dtreefont dtree-theme-ficon"></span><input type="checkbox" class="aaa"  area_deep="'+v.area_deep+'" value="'+v.area_id+'" ids="'+v.last_ids+'" data_name="'+v.top_name+'" > '+v.area_name+' <div class="last'+v.area_id +'" style="padding-left:20px; margin:10px;"></div>';
                }else{
                     htmls+='<i class="dtree-icon-shuye1 dtreefont-special dtree-theme-dtreefont dtree-theme-icon"></i>'+'<input type="checkbox" id="p3"  ids="'+v.area_id+'"    area_deep="'+v.area_deep+'" data_name="'+v.top_name+'" class="aaa" >'+v.area_name;
                }
                });
              if( $(".sec"+choose_id).length>0){
                $(".sec"+choose_id).html(htmls);
               obj.attr("class","area_hidden dtree-theme-dtreefont dtree-theme-ficon dtreefont dtree-icon-jian");
      }else{
                $(".last"+choose_id).html(htmls);
                obj.attr("class","area_hidden dtree-theme-dtreefont dtree-theme-ficon dtreefont dtree-icon-jian");
            }
                if (obj.next().prop('checked')) {
                    obj.next().next().find('input:checkbox').prop('checked', true);
                } else {
                    $('input[name="checkall"]').prop('checked', false);
                    obj.next().next().find('input:checkbox').prop('checked', false);
                }
}
        })


});

     $(document).on('click', '.area_hidden', function() {
    var choose_id = $(this).next().val();
    $(".sec"+choose_id).empty();
    $(".last"+choose_id).empty();
    var obj = $(this);
     obj.attr("class","select_choose dtreefont dtree-icon-jia dtree-theme-dtreefont dtree-theme-ficon");
});

      //点击地区复选框
      $(document).on('click', 'input:checkbox', function () {
          if ($(this).attr('area_deep') == 2) {
              if ($(this).prop('checked')) {
                  $(this).next().find('input:checkbox').prop('checked', true);
              } else {
                  $('input[name="checkall"]').prop('checked', false);
                  //子集
                  $(this).next().find('input:checkbox').prop('checked', false);
                  //顶级
                  $(this).parent('div').parent('div').find('input:checkbox:first').prop('checked', false);
              }
          } else if ($(this).attr('area_deep') == 1) {

              if ($(this).prop('checked')) {
                  $(this).parent('div').find('input:checkbox').prop('checked', true);
              } else {
                  $('input[name="checkall"]').prop('checked', false);
                  $(this).parent('div').find('input:checkbox').prop('checked', false);
              }

          } else {

              if (!$(this).prop('checked')) {
                  $('input[name="checkall"]').prop('checked', false);
                  $(this).parent('div').parent('div').find('input:checkbox').first().prop('checked', false);
                  $(this).parent('div').parent('div').parent('div').find('input:checkbox').first().prop('checked', false);
              }

          }
      });

});





</script>


 {/block}



